//
//  WJTabBarController.m
//  BeDeJie
//
//  Created by jerry on 2017/1/25.
//  Copyright © 2017年 jerry. All rights reserved.
//

#import "WJTabBarController.h"
#import "WJNavigationController.h"
#import "WJEssenceViewController.h"
#import "WJNewViewController.h"
#import "WJFriendTrendViewController.h"
#import "WJMeViewController.h"
#import "WJTabBar.h"

@interface WJTabBarController ()

@end

@implementation WJTabBarController

+(void) load {
    //获取哪个类下的UITabBarItem
    UITabBarItem *tabBarItem = [UITabBarItem appearanceWhenContainedIn:self, nil];
    
    //设置按钮选中时标题的颜色
    //创建一个描述文本属性的字典
    NSMutableDictionary *attrsColor = [NSMutableDictionary dictionary];
    attrsColor[NSForegroundColorAttributeName] = [UIColor blackColor];
    [tabBarItem setTitleTextAttributes:attrsColor forState:UIControlStateSelected];
    
    //设置字体尺寸。字体尺寸只有在正常状态下，才有效果
    NSMutableDictionary *attrsFont = [NSMutableDictionary dictionary];
    attrsFont[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [tabBarItem setTitleTextAttributes:attrsFont forState:UIControlStateNormal];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 添加子控制器
    [self setupChildViewController];
    
    // 设置TabBar上的内容
    [self setupTabBarButton];
    
    // 自定义TabBar
    [self setupCustomTabBar];
    
}

-(void) setupChildViewController {
    //精华控制器
    WJEssenceViewController *essenceViewController = [[WJEssenceViewController alloc] init];
    WJNavigationController *navEssenceController = [[WJNavigationController alloc] initWithRootViewController:essenceViewController];
    [self addChildViewController:navEssenceController];
    
    //新帖控制器
    WJNewViewController *newViewController = [[WJNewViewController alloc] init];
    WJNavigationController *navNewController = [[WJNavigationController alloc] initWithRootViewController:newViewController];
    [self addChildViewController:navNewController];
    
    //关注控制器
    WJFriendTrendViewController *friendTrendViewController = [[WJFriendTrendViewController alloc] init];
    WJNavigationController *navFriendTrendController = [[WJNavigationController alloc] initWithRootViewController:friendTrendViewController];
    [self addChildViewController:navFriendTrendController];
    
    //我控制器
    UIStoryboard *meStoryboard = [UIStoryboard storyboardWithName:NSStringFromClass([WJMeViewController class]) bundle:nil];
    //加载箭头指向的那个控制器
    WJMeViewController *meViewController = [meStoryboard instantiateInitialViewController];
    WJNavigationController *navMeController = [[WJNavigationController alloc] initWithRootViewController:meViewController];
    [self addChildViewController:navMeController];
    
}

-(void) setupTabBarButton {
    //精华按钮
    UINavigationController *navEssenceController = self.childViewControllers[0];
    navEssenceController.tabBarItem.title = @"精华";
    navEssenceController.tabBarItem.image = [UIImage imageNamed:@"icon_tabBar_essence_normal"];
    navEssenceController.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"icon_tabBar_essence_selected"];
    
    //新帖按钮
    UINavigationController *navNewController = self.childViewControllers[1];
    navNewController.tabBarItem.title = @"新帖";
    navNewController.tabBarItem.image = [UIImage imageNamed:@"icon_tabBar_new_normal"];
    navNewController.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"icon_tabBar_new_selected"];

    //关注按钮
    UINavigationController *navFriendTrendController = self.childViewControllers[2];
    navFriendTrendController.tabBarItem.title = @"关注";
    navFriendTrendController.tabBarItem.image = [UIImage imageNamed:@"icon_tabBar_friendTrends_normal"];
    navFriendTrendController.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"icon_tabBar_friendTrends_selected"];

    //我按钮
    UINavigationController *navMeController = self.childViewControllers[3];
    navMeController.tabBarItem.title = @"我";
    navMeController.tabBarItem.image = [UIImage imageNamed:@"icon_tabBar_me_normal"];
    navMeController.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"icon_tabBar_me_selected"];

}

-(void) setupCustomTabBar {
    WJTabBar *tabBar = [[WJTabBar alloc] init];
    tabBar.backgroundImage = [UIImage imageNamed:@"tabbar_light"];
    //
    [self setValue:tabBar forKey:@"tabBar"];
}

@end
